from rest_framework import viewsets, permissions

from diarys.models import Diary
from diarys.serializers import DiarySerializer
from diarys.permissions import IsBelongUser
# Create your views here.


class DiaryViewSet(viewsets.ModelViewSet):
    queryset = Diary.objects.all()
    serializer_class = DiarySerializer
    permission_classes = (permissions.IsAuthenticated, IsBelongUser)

    def perform_create(self, serializer):
        serializer.save(user=self.request.user)

    def get_queryset(self):
        return Diary.objects.filter(user=self.request.user)
